package com.yangyouli.unity_demo_server.controller;

import java.util.List;

import com.yangyouli.unity_demo_server.annotation.Inject;
import com.yangyouli.unity_demo_server.annotation.ResponseClass;
import com.yangyouli.unity_demo_server.annotation.ResponseMethod;
import com.yangyouli.unity_demo_server.entity.UserData;
import com.yangyouli.unity_demo_server.server.Client;
import com.yangyouli.unity_demo_server.server.RoomObj;
import com.yangyouli.unity_demo_server.service.UserDataService;
import com.yangyouli.unity_demo_server.util.ThreadLocalHelper;

@ResponseClass("add")
public class AddController {

	@Inject
	UserDataService userDataService;
	
	@ResponseMethod("exp")
	public String addExp (String data) {
		Client client = ThreadLocalHelper.getClient();
		RoomObj roomObj = client.getRoomObj();
		UserData userData = new UserData();
		userData.setUserId(client.getUserId());
		userData.setExp(roomObj.getAlivePlayerNum() > 0 ? 100 + client.getAddExp() : client.getAddExp());
		userDataService.addExp(userData);
		
		return "" + userData.getExp();
	}
	
	@ResponseMethod("money")
	public String addMoney (String data) {
		Client client = ThreadLocalHelper.getClient();
		RoomObj roomObj = client.getRoomObj();
		UserData userData = new UserData();
		userData.setUserId(client.getUserId());
		userData.setMoney(roomObj.getAlivePlayerNum() > 0 ? 70 + client.getAddMoney() : client.getAddMoney());
		userDataService.addMoney(userData);
		return "" + userData.getMoney();
	}
}
